package com.taotao.order.controller;

import com.taotao.order.service.OrderService;
import com.taotao.pojo.form.OrderForm;
import com.taotao.util.ExceptionUtil;
import com.taotao.util.TaotaoResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author hong.zheng
 * @Description
 * @date 2018-09-30-9:46
 **/
@Controller
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/create")
    @ResponseBody
    public TaotaoResult createOrder(@RequestBody OrderForm orderForm) {
        try {
            TaotaoResult result = orderService.createOrder(orderForm, orderForm.getOrderItems(), orderForm.getOrderShipping());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
        }
    }
}
